package com.gzy.exams.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzy.exams.entity.Users;
import com.gzy.exams.service.UsersService;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("users")
public class UsersController {

    @Resource
    private UsersService usersService;

    /**
     * 分页查询
     *
     * @param users 筛选条件
     * @param pageable 分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Users>> queryByPage(Users users, @PageableDefault(size = 10, sort = "userId") Pageable pageable) {
        // 将 Spring Data 的 Pageable 转换为 MyBatis Plus 的 Page
        Page<Users> page = new Page<>(pageable.getPageNumber() + 1, pageable.getPageSize());
        return ResponseEntity.ok(this.usersService.queryByPage(users, page));
    }
}
